package com.zt.event.service.status.listener;

import com.zt.event.enums.ApplicationStatusEnums;
import com.zt.event.service.status.event.CustomsApplicationFailedEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * @author system
 * 服务启动失败
 */
@Slf4j
@Component
@EnableAsync
public class ServiceFailedListener extends DefaultListenerProcess implements ApplicationListener<CustomsApplicationFailedEvent>{


    @Override
    public void onApplicationEvent(CustomsApplicationFailedEvent event) {
        log.error("服务启动失败");
        ConfigurableApplicationContext applicationContext = event.getApplicationContext();
        String response = defaultHandleMessage(ApplicationStatusEnums.SERVER_FAILED, event.getException().getCause().getMessage(),
                applicationContext,event.getCostTime());
        if (response == null) {
            log.info("NOTICE_URL 参数为空, 不参与发送");
        } else {

            log.info("send success data:{}", response);
        }
    }
}
